#include <iostream>
#include <sys/types.h>
#include <sys/stat.h>
#include <fcntl.h>
#include <unistd.h>
#include <string>
using namespace std;
#define BUFFERSIZE 1024
#define PIPENAME "./mypipe"
#define PIPEMODE 0664

#include "log.hpp"
Log log;

//枚举适用于有限的取值的类型
enum ERRCODE
{
    //常量，常量的值由第一个开始+1递增
    FIFO_CREATE_ERR = 1,
    FIFO_DELETE_ERR,
    FIFO_OPEN_ERR
};


struct InitNamePipe
{
    InitNamePipe()
    {
        int mkfifoRet = mkfifo(PIPENAME,PIPEMODE);
        if(mkfifoRet == -1)
        {
            //报错并打印日志
            perror("mkfifo");
            log(FATAL,"mkfifo:%d=%s",errno,strerror(errno));
            exit(FIFO_CREATE_ERR);
        }
        log(INFO,"mkfifo:%d=%s",errno,strerror(errno));
    }
    ~InitNamePipe()
    {
        int unlinkRet = unlink(PIPENAME);
        if(unlinkRet == -1)
        {
            //报错并打印日志
            perror("unlink");
            log(FATAL,"unlink:%d=%s",errno,strerror(errno));
            exit(FIFO_DELETE_ERR);
        }
        log(INFO,"unlink:%d=%s",errno,strerror(errno));
    }
};